package com.example.demo.message;

import com.example.demo.request.WxRequest;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlCData;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JacksonXmlRootElement(localName = "xml")
public class Message {

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "MsgType")
    private String msgType; //消息类型 判断是事件还是非事件

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "ToUserName")
    private String toUserName; //用户openID

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "FromUserName")
    private String fromUserName; //公众号原始ID

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "CreateTime")
    private Long createTime; //时间戳  单位 秒

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "Content")
    private String content; //文本消息内容

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "MediaId")
    private String mediaId; //视频消息媒体id，可以调用获取临时素材接口拉取数据。

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "Format")
    private String format;

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "MsgId")
    private String msgId; //消息id，64位整型

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "ThumbMediaId")
    private String thumbMediaId; //视频消息缩略图的媒体id，可以调用多媒体文件下载接口拉取数据。

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "Location_X")
    private String locationX;

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "Location_Y")
    private String locationY;

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "Scale")
    private String scale;

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "Label")
    private String label;

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "Event")
    private String event;

    @JacksonXmlCData
    @JacksonXmlProperty(localName = "EventKey")
    private String eventKey;

    public Message(WxRequest wxRequest) {
        setToUserName(wxRequest.getFromUserName());
        setFromUserName(wxRequest.getToUserName());
        setCreateTime(System.currentTimeMillis()/1000);
        setMsgType("text");
        setContent(wxRequest.getContent());
    }
}
